package test.hystrix.serviceb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import test.hystrix.serviceb.remote.IdcardService;

@RestController
@RequestMapping("/test/hystrix")
public class MainController {
    @Autowired
    IdcardService idcardService;

    @GetMapping("/token")
    public String callServiceAToken(){
        return idcardService.token();
    }

    /**
     * 触发熔断，默认在 20 次失败中 有 50% 失败会触发熔断
     * @return
     */
    @GetMapping("/triggerBreaker")
    public String triggerBreaker(){
        for (int i = 0; i < 20; i++) {
            idcardService.token();
        }
        return idcardService.token();
    }
}
